package 简单题目;

public class 重复词2 {

	public static void main(String[] args) {

	}

	class Periods {
		public long getLongest(int n, String s) {
			// 动态规划
			int[] dp = new int[n];
			char[] c = s.toCharArray();

			for (int i = n - 1; i > 0; i--) {
				if (c[i] == c[0]) {
					for (int j = 0, k = i; k < n; j++, k++) {
						if (c[j] == c[k])
							dp[k] = Math.max(dp[k], i);
						else
							break;
					}
				}
			}

			// 求结果，累加
			long res = 0;
			for (int r : dp)
				res += r;
			return res;
		}
	}
}
